/**
 * Metric Unit Tests
 * Tests convert and toUnit for each Unit Type
 */
package cmsc495.mach2.test.unit;

import cmsc495.mach2.unit.MetricUnit;
import junit.framework.TestCase;

/**
 * @author Michael Swann
 * 
 */
public class MetricUnitValidation extends TestCase {

	// Amount of Error Allowed
	private static final double			DELTA						= 0.01;

	private static final double			KILO_VALUE					= 0.001;
	private static final double			HECTO_VALUE					= 0.01;
	private static final double			DECA_VALUE					= 0.1;
	private static final double			BASE_VALUE					= 1.0;
	private static final double			DECI_VALUE					= 10.0;
	private static final double			CENTI_VALUE					= 100.0;
	private static final double			MILLI_VALUE					= 1000.0;

	// English Value of Base Unit
	private static final double			ENGLISH_SQUAREINCHES_VALUE	= 1550.0031;
	private static final double			ENGLISH_DRY_QUARTS_VALUE	= 0.9080829782;
	private static final double			ENGLISH_INCHES_VALUE		= 39.3700787;
	private static final double			ENGLISH_OUNCES_VALUE		= 0.0352739619;
	private static final double			ENGLISH_CUBICINCHES_VALUE	= 61023.7441;
	private static final double			ENGLISH_WET_QUARTS_VALUE	= 1.05668821;

	private static final double			values[]					= { KILO_VALUE, HECTO_VALUE, DECA_VALUE, BASE_VALUE, DECI_VALUE, CENTI_VALUE, MILLI_VALUE };
	private static final MetricUnit[]	metricUnits					= MetricUnit.values();

	public MetricUnitValidation() {
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#convert(double, mach2convert.englishunit.MetricUnit)}
	 * .
	 */
	public final void testConvert() {
		for (int i = 0; i < metricUnits.length; i++) {
			for (int j = 0; j < metricUnits.length; j++) {
				System.out.println("ASSERT: " + values[i] + " " + metricUnits[i] + ".convert(" + values[j] + ", " + metricUnits[j] + "))");
				assertEquals(values[i], metricUnits[i].convert(values[j], metricUnits[j]), DELTA);
			}
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toKilo(double)}.
	 */
	public final void testToKilos() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toKilo(values[i]);
			System.out.println("ASSERT: " + KILO_VALUE + " = " + result + " " + metricUnits[i] + ".toKilo(" + values[i] + ") ");
			assertEquals(KILO_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toHecto(double)}.
	 */
	public final void testToHecto() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toHecto(values[i]);
			System.out.println("ASSERT: " + HECTO_VALUE + " = " + result + " " + metricUnits[i] + ".toHecto(" + values[i] + ") ");
			assertEquals(HECTO_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toDeca(double)}.
	 */
	public final void testToDeca() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toDeca(values[i]);
			System.out.println("ASSERT: " + DECA_VALUE + " = " + result + " " + metricUnits[i] + ".toDeca(" + values[i] + ") ");
			assertEquals(DECA_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toBase(double)} .
	 */
	public final void testToBase() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toBase(values[i]);
			System.out.println("ASSERT: " + BASE_VALUE + " = " + result + " " + metricUnits[i] + ".toBase(" + values[i] + ") ");
			assertEquals(BASE_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toDeci(double)}.
	 */
	public final void testToDeci() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toDeci(values[i]);
			System.out.println("ASSERT: " + DECI_VALUE + " = " + result + " " + metricUnits[i] + ".toDeci(" + values[i] + ") ");
			assertEquals(DECI_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toCenti(double)}.
	 */
	public final void testToCenti() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toCenti(values[i]);
			System.out.println("ASSERT: " + CENTI_VALUE + " = " + result + " " + metricUnits[i] + ".toCenti(" + values[i] + ") ");
			assertEquals(CENTI_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toMilli(double)}.
	 */
	public final void testToMilli() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toMilli(values[i]);
			System.out.println("ASSERT: " + MILLI_VALUE + " = " + result + " " + metricUnits[i] + ".toMilli(" + values[i] + ") ");
			assertEquals(MILLI_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toEnglishSquareInches(double)}
	 * .
	 */
	public final void testToEnglishSquareInches() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toEnglishSquareInches(BASE_VALUE);
			System.out.println("ASSERT: " + ENGLISH_SQUAREINCHES_VALUE * values[i] + " = " + result + " " + metricUnits[i] + ".toEnglishSquareInches(" + BASE_VALUE + ") ");
			assertEquals(ENGLISH_SQUAREINCHES_VALUE * values[i], result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toEnglishDryQuarts(double)}.
	 */
	public final void testToEnglishDryQuarts() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toEnglishDryQuarts(BASE_VALUE);
			System.out.println("ASSERT: " + ENGLISH_DRY_QUARTS_VALUE * values[i] + " = " + result + " " + metricUnits[i] + ".toEnglishDryQuarts(" + BASE_VALUE + ") ");
			assertEquals(ENGLISH_DRY_QUARTS_VALUE * values[i], result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toEnglishInches(double)}.
	 */
	public final void testToEnglishInches() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toEnglishInches(BASE_VALUE);
			System.out.println("ASSERT: " + ENGLISH_INCHES_VALUE * values[i] + " = " + result + " " + metricUnits[i] + ".toEnglishInches(" + BASE_VALUE + ") ");
			assertEquals(ENGLISH_INCHES_VALUE * values[i], result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toEnglishOunces(double)}.
	 */
	public final void testToEnglishOunces() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toEnglishOunces(BASE_VALUE);
			System.out.println("ASSERT: " + ENGLISH_OUNCES_VALUE * values[i] + " = " + result + " " + metricUnits[i] + ".toEnglishOunces(" + BASE_VALUE + ") ");
			assertEquals(ENGLISH_OUNCES_VALUE * values[i], result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toEnglishCubicInches(double)}.
	 */
	public final void testToEnglishCubicInches() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toEnglishCubicInches(BASE_VALUE);
			System.out.println("ASSERT: " + ENGLISH_CUBICINCHES_VALUE * values[i] + " = " + result + " " + metricUnits[i] + ".toEnglishCubicInches(" + BASE_VALUE + ") ");
			assertEquals(ENGLISH_CUBICINCHES_VALUE * values[i], result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.MetricUnit#toEnglishWetQuarts(double)}.
	 */
	public final void testToEnglishWetQuarts() {
		for (int i = 0; i < metricUnits.length; i++) {
			double result = metricUnits[i].toEnglishWetQuarts(BASE_VALUE);
			System.out.println("ASSERT: " + ENGLISH_WET_QUARTS_VALUE * values[i] + " = " + result + " " + metricUnits[i] + ".toEnglishWetQuarts(" + BASE_VALUE + ") ");
			assertEquals(ENGLISH_WET_QUARTS_VALUE * values[i], result, DELTA);
		}
	}
}
